import request from '@/utils/request'

export function login(data) {
  return request({
    url: '/users/login',
    method: 'post',
    data
  })
}

export function logout() {
  return request({
    url: '/users/logout',
    method: 'post'
  })
}

export function getUserInfo(token) {
  return request({
    url: `/users/info/${token}`,
    method: 'get'
  })
}

export function fetchUserList() {
  return request({
    url: '/users',
    method: 'get'
  })
}

export function fetchUserById(id) {
  return request({
    url: `/users/${id}`,
    method: 'get'
  })
}

export function fetchUserByEmail(email) {
  return request({
    url: `/users/${email}`,
    method: 'get'
  })
}

export function createUser(data) {
  return request({
    url: '/users',
    method: 'post',
    data
  })
}

export function updateUser(id, data) {
  return request({
    url: `/users/${id}`,
    method: 'put',
    data
  })
}

export function deleteUser(id) {
    return request({
      url: `/users/${id}`,
      method: 'delete'
    })
}
